#include "sensordialog.h"
#include "ui_sensordialog.h"

SensorDialog::SensorDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SensorDialog)
{
    ui->setupUi(this);

    this->f_clockform = new clockform;

    ui->stackedWidget_clock->addWidget(this->f_clockform);
    ui->stackedWidget_clock->setCurrentWidget(this->f_clockform);
}

SensorDialog::~SensorDialog()
{
    delete ui;
}

void SensorDialog::on_pushButton_listen_clicked()
{/*
    tcpserver = new QTcpServer(this);

    this->tcpserver->listen(QHostAddress::Any,ui->lineEdit_port->text().toInt());

    connect(this->tcpserver,SIGNAL(newConnection()),this,SLOT(processConnection()));*/
    static int time = 0;
    this->f_clockform->setCurrentClock(time++%13);
}

void SensorDialog::processConnection(){
    this->pTcpSocketServer = this->tcpserver->nextPendingConnection();
    this->connect(pTcpSocketServer,SIGNAL(readyRead()),this,SLOT(processText()));
}

void SensorDialog::processText(){
    QString msg = this->pTcpSocketServer->readAll();

    switch(msg.at(0).toAscii()){
    case 'T':
        ui->lineEdit_temp->setText(msg);
        break;
    case 'S':
        ui->lineEdit_speed->setText(msg);
        break;
    default:
        break;
    }
}
